<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div#top{
            width: 100px;
            height: 100px;
            background-color: red;
        }
        div#bottom{
            width: 200px;
            height: 200px;
            background-color: blue;
        }
        div{
            margin: 20px;

        }
    </style>
    <script>
        window.onload=function(){
            var top=document.getElementById('top');
            var bottom=document.getElementById('bottom');
            top.ondragstart=function(event){
                var data=event.dataTransfer;
                data.setData('text',this.id);

                //设置拖动的图片
                var img=document.createElement('img');
                img.src='./qq.png'
                data.setDragImage(img,50,50);

                //设置拖动时鼠标的样式
                data.effectAllowed='link';
                //清除之后，就获取不到了
                // data.clearData('text')
            
            }
            
            bottom.ondragover=function(event){
                event.preventDefault();
                //设置拖动时鼠标的样式
                event.dataTransfer.dropEffect='link';
                
            }
            bottom.ondrop=function(event){
                //组织打开空白页面
                event.preventDefault();
                event.stopPropagation();
                var id=event.dataTransfer.getData('text');
                var top=document.getElementById(id);
                //获取文本内容，并赋值给第三方变量
                var topText=top.innerHTML; 
                var bottomText=this.innerHTML;
                //传值
                this.innerHTML=topText;
                top.innerHTML=bottomText;
                
                

            }

        }
    </script>
</head>
<body>
    <div id="top" draggable="true">
        <h1>hello</h1>
    </div>
    <div id="bottom">
        <h1>world</h1>
    </div>
</body>
</html>